package com.zds.filter;

import javax.servlet.*;
import java.io.IOException;

public class LogFilter implements Filter {
    private String site;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //获取初始化参数
        site = filterConfig.getInitParameter("site");
        //输出初始化参数
        System.out.println("拦截器调用init()");
        System.out.println("网站名："+site);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//        chain.doFilter(request,response);
        if ("bilibili".equals(site)){
            System.out.println("拦截器调用doFilter()");
            chain.doFilter(request, response);
        }else {
            System.out.println("方法已经被拦截，网页失效");
        }
    }

    @Override
    public void destroy() {
        System.out.println("拦截器调用destory()");
    }
}
